package action;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.xml.transform.Result;
import java.text.Normalizer;
import java.util.Date;


@Controller
public class Action {
    @RequestMapping("getStr")
   @ResponseBody
  public String getStr() throws Exception{
               return "你好 spring boot 222";
           }

           @GetMapping("getNumber")
  @ResponseBody
    public int getNumber() throws Exception{


                             return 100;
            }

        @GetMapping("getABoolean")
  @ResponseBody
   public boolean getBoolean() throws Exception{
               return true;
          }

            @GetMapping("getDate")
    @ResponseBody
+   public Date getDate() throws Exception{
                return new Date();
           }




           @PostMapping("BMI")
    @ResponseBody
    public Result bMI(@RequestBody Normalizer.Form form) throws Exception{

                       float sgf=Float.valueOf(form.getSg());
                float tzf=Float.valueOf(form.getTz());
              float result=0.0f;
                result=tzf/(sgf*sgf);


                                String resultstr="";+
                       if(result<18.5){
                        resultstr="过轻";
                   }
               else if(result>=18.5&&result<=23.9){
                       resultstr="正常";
                    }
               else  if(result>=24&&result<=27){
                        resultstr="过重";
                   }
               else if(result>=28&&result<32){
                       resultstr="肥胖";
                    }
                else {
                       resultstr="严重肥胖";
                    }

                        String suggest="";

                        switch (resultstr){
                        case "过轻":
                            suggest="多吃点";
                            break;
                        case "正常":
                               suggest="继续保持";
                                break;
                        case "过重":
                                suggest="减肥啦";
                                break;

                                case "肥胖":
                                suggest="吃点减肥药";
                                break;
                            default:
                                   suggest="绝食吧";
                       }


                                Result ro=new Result();
                ro.setResult(result);
                ro.setResultstr(resultstr);
               ro.setSuggest(suggest);




               return ro;



           }

}
